package lsf.itcast.service.imp;

import lsf.itcast.dao.RoleDao;
import lsf.itcast.domain.Permission;
import lsf.itcast.domain.Role;
import lsf.itcast.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class RoleServiceImp implements RoleService{
    @Autowired
    private RoleDao roleDao;
    @Override
    public List<Role> findAll() {
        return roleDao.findAll();
    }

    @Override
    public void save(Role role) {
        roleDao.save(role);
    }

    @Override
    public List<Role> findOtherRole(String userId) {
        return roleDao.findOtherRole(userId);
    }

    @Override
    public Role findById(String roleId) {
        return roleDao.findById(roleId);
    }

    @Override
    public void addPermissionToRole(String roleId,String[] ids) {
        for (int i = 0; i < ids.length; i++) {
            roleDao.addPermissionToRole(roleId,ids[i]);
        }

    }
}
